package controller.action;

import javax.servlet.http.HttpSession;

import model.service.loginService;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class login extends ActionSupport{
	private String result;
	private  loginService loginServ;
	private String userInfo;
	private  String propertyName;
	private String propertyInfo;
	
	private HttpSession session;
	public void setUserInfo(String userInfo) {
		this.userInfo = userInfo;
	}
	public String getResult() {
		return result;
	}
	
	public void setPropertyInfo(String propertyInfo) {
		this.propertyInfo = propertyInfo;
	}
	public void setLoginServ(loginService loginServ) {
		this.loginServ = loginServ;
	}
	
	public void setPropertyName(String propertyName) {
		this.propertyName = propertyName;
	}
	public String login()
	{
		session = ServletActionContext.getRequest().getSession();
		result = loginServ.login(userInfo,session);
		System.out.println(session.getAttribute("isLogin"));
		return SUCCESS;
	}
	public String logout()
	{
		session = ServletActionContext.getRequest().getSession();
		session.invalidate();
		result = "success";
		return SUCCESS;
	}
	public String setSessionPara()
	{
		session = ServletActionContext.getRequest().getSession();
		session.setAttribute(propertyName,propertyInfo);
		result="success";
		return SUCCESS;
	}
	public String getSessionPara()
	{
		session = ServletActionContext.getRequest().getSession();
		System.out.println(propertyName);
		System.out.println(session.getAttribute(propertyName));
		if(session.getAttribute(propertyName)==null)
			result = "false";
		else
			result = (String) session.getAttribute(propertyName);
		System.out.println(result);
		return SUCCESS;
	}
	

}
